package com.ruoyi.awards.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.awards.domain.JwCompetitionAwards;
import com.ruoyi.awards.service.IJwCompetitionAwardsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 竞赛获奖情况Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/awards/awards")
public class JwCompetitionAwardsController extends BaseController
{
    @Autowired
    private IJwCompetitionAwardsService jwCompetitionAwardsService;

    /**
     * 查询竞赛获奖情况列表
     */
    @PreAuthorize("@ss.hasPermi('awards:awards:list')")
    @GetMapping("/list")
    public TableDataInfo list(JwCompetitionAwards jwCompetitionAwards)
    {
        startPage();
        List<JwCompetitionAwards> list = jwCompetitionAwardsService.selectJwCompetitionAwardsList(jwCompetitionAwards);
        return getDataTable(list);
    }

    /**
     * 导出竞赛获奖情况列表
     */
    @PreAuthorize("@ss.hasPermi('awards:awards:export')")
    @Log(title = "竞赛获奖情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JwCompetitionAwards jwCompetitionAwards)
    {
        List<JwCompetitionAwards> list = jwCompetitionAwardsService.selectJwCompetitionAwardsList(jwCompetitionAwards);
        ExcelUtil<JwCompetitionAwards> util = new ExcelUtil<JwCompetitionAwards>(JwCompetitionAwards.class);
        util.exportExcel(response, list, "竞赛获奖情况数据");
    }

    /**
     * 获取竞赛获奖情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('awards:awards:query')")
    @GetMapping(value = "/{caId}")
    public AjaxResult getInfo(@PathVariable("caId") Long caId)
    {
        return success(jwCompetitionAwardsService.selectJwCompetitionAwardsByCaId(caId));
    }

    /**
     * 新增竞赛获奖情况
     */
    @PreAuthorize("@ss.hasPermi('awards:awards:add')")
    @Log(title = "竞赛获奖情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JwCompetitionAwards jwCompetitionAwards)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        jwCompetitionAwards.setDeptId(104L);
        jwCompetitionAwards.setUserId(user.getUserId());
        return toAjax(jwCompetitionAwardsService.insertJwCompetitionAwards(jwCompetitionAwards));
    }

    /**
     * 修改竞赛获奖情况
     */
    @PreAuthorize("@ss.hasPermi('awards:awards:edit')")
    @Log(title = "竞赛获奖情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JwCompetitionAwards jwCompetitionAwards)
    {
        return toAjax(jwCompetitionAwardsService.updateJwCompetitionAwards(jwCompetitionAwards));
    }

    /**
     * 删除竞赛获奖情况
     */
    @PreAuthorize("@ss.hasPermi('awards:awards:remove')")
    @Log(title = "竞赛获奖情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caIds}")
    public AjaxResult remove(@PathVariable Long[] caIds)
    {
        return toAjax(jwCompetitionAwardsService.deleteJwCompetitionAwardsByCaIds(caIds));
    }
}
